mod utils;

use std::env;

#[tokio::main]
async fn main() {
    const VERSION:&str = "0.1.0";
    let args: Vec<String> = env::args().collect();

    if args.len()<2 || args[1] == "-h" || args[1] == "-help" {
        println!("Zig's package manager\n");
        println!("Usage: zigup [-options] [args]\n");
        println!("Options:\n  -v,-version 打印版本信息并退出");
        println!("  -i,-install [版本]  安装版本的zig");
        println!("  -rm,-remove [版本]  移除版本的zig");
        println!("  -h,-help 查看帮助");
        return;
    }else if args[1] =="-v" || args[1]=="-version" { 
        println!("{VERSION}");
    }else if args[1] =="-i" || args[1] == "-install" {
        let mut version :Option<String> = None;
        
        if args.len()>2 {
            version = Some(args[2].to_string());
        }
        match utils::Installer::new().install_zig(version).await {
            Ok(_) => println!("安装成功！"),
            Err(e) => println!("{}",e),
        }
        std::process::exit(0);
    }else { 
        println!("参数错误 \n执行 -h 获取帮助信息");
        std::process::exit(0);
    }

}
